package com.zk.yygh.hosp.controller;

import com.zk.yygh.hosp.mapper.ScheduleMapper;
import com.zk.yygh.hosp.result.Result;
import com.zk.yygh.hosp.service.ScheduleService;
import com.zk.yygh.model.hosp.Schedule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: 张凯
 * @date: 2022/6/8 - 16:29
 */
@Api("排班相关")
@RestController
//@CrossOrigin
@RequestMapping("/admin/hosp/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private ScheduleMapper scheduleMapper;

    @ApiOperation("1.根据医院编号和科室编号分页查询排班规则")
    @GetMapping("getScheduleRule/{hoscode}/{depcode}/{page}/{limit}")
    public Result getScheduleRule(@PathVariable("hoscode") String hoscode,
                                  @PathVariable("depcode") String depcode,
                                  @PathVariable("page") Integer page,
                                  @PathVariable("limit") Integer limit){
        Map<String, Object> map = scheduleService.getScheduleRole(hoscode, depcode, page, limit);
        return Result.ok(map);
    }

    @ApiOperation("2.根据医院编号科室编号日期查询具体排班信息")
    @GetMapping("getScheduleDetail/{hoscode}/{depcode}/{workDate}")
    public Result getScheduleDetail(@PathVariable("hoscode") String hoscode,
                                    @PathVariable("depcode") String depcode,
                                    @PathVariable("workDate") String workDate){
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return Result.ok(scheduleList);
    }

    @ApiOperation("3.远程调用根据id获取排班信息")
    @GetMapping("getScheduleById/{id}")
    public Schedule getScheduleById(@PathVariable("id") String id){
        return scheduleMapper.selectById(id);
    }

    @ApiOperation("4.远程调用更新排班信息")
    @PostMapping("update/schedule")
    public void updateSchedule(@RequestBody Schedule schedule){
        scheduleMapper.updateById(schedule);
    }
}
